package code1_100.code11_20;

import java.util.Stack;

public class Code20 {




}

/**
 * 使用栈进行判断
 */
class Solution {
    public boolean isValid(String s) {
        char[] chars = s.toCharArray();
        Stack<Character> stack = new Stack<Character>();
        for (char aChar : chars) {
            if (stack.empty())
                stack.add(aChar);
            else {
                if (stack.lastElement() + 1 == aChar || stack.lastElement() + 2 == aChar) {
                    stack.pop();
                } else {
                    stack.push(aChar);
                }
            }
        }
        return stack.isEmpty();

    }

    public static void main(String[] args) {

        System.out.println(new Solution().isValid("({[)"));
    }
}
